<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/public/header/permissionCommon.jspf" %>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>长护险项目管理系统-飞行检查编辑</title>
    <script>

        <%--    编辑表单记录保存--%>
        $(function (){
            $("#save_btn").click(function (){
                //alert($("#newcheckForm").serialize());
                var updaterecordId = $("#recordID").val();
                var adminID=$("#adminID").val();
                var adminName=$("#adminName").val();
                var hgID=$("#hgID").val();
                var hgName=$("#hgName").val();
                var checkTime=$("#checkdate").val();
                var checkResult=$("#checkresult").val();
                var recordFile=$("#filePath").val();
                var checkDescribe=$("#checkDescribe").val();


                $.ajax({
                    url:"${webPath}/toTempCheck/record/"+updaterecordId,
                    type:"POST",
                    data:"admin_id="+adminID
                        +"&admin_name="+adminName
                        +"&hg_id="+hgID
                        +"&hg_name="+hgName
                        +"&check_time="+checkTime
                        +"&checkresult="+checkResult
                        +"&recordfile="+recordFile
                        +"&checkdescribe="+checkDescribe,
                    // contentType:false,
                    success:function (result){
                        //alert(result.msg);
                        //当你在iframe页面关闭自身时
                        var index =parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭

                    },
                    fail:function (result){
                        alert(result.msg);
                    }
                })

                // //获取表单输入框相关数据
                // var adminName=$("#adminName").val();
                // var userName=$("#userName").val();
                // var checkTime=$("#checkTime").val();
                // var result=$("input[name='result']").val();
                // var file=$("#file").val();
                // var describe=$("#describe").val();
                //
                // //动态添加表单行
                // var $trObj=$("<tr>" +
                //     "         <td>"+"1"+"</td>" +
                //     "         <td>"+adminName+"</td>" +
                //     "         <td>"+userName+"</td>" +
                //     "         <td>"+checkTime+"</td>" +
                //     "         <td>"+result+"</td>" +
                //     "         <td>"+file+"</td>" +
                //     "         <td>"+describe+"</td>" +
                //     "</tr>");


            })
        })

    </script>
</head>
<body >
<div>
<%--    <!-- 头部和左侧导航-->--%>
<%--    <div id="header"></div>--%>

    <!-- 主体 -->
    <div style="margin: auto;margin-top: 1%">
        <%--<div class="demoTable">--%>
        <%--&nbsp;&nbsp;<button class="layui-btn" onclick="addPerm('{{r.id}}',0)">开通权限</button>--%>
        <%--</div>--%>
            <form id="newcheckForm" class="layui-form" >
                <div class="layui-form-item">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-inline">
                        <input  id="recordID" type="text" autocomplete="off" lay-verify="required"  class="layui-input" disabled="disabled">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员ID</label>
                    <div class="layui-input-inline">
                        <input name="admin_id" id="adminID" type="text" autocomplete="off" lay-verify="required" placeholder="请输入管理员ID" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">管理员姓名</label>
                    <div class="layui-input-inline">
                        <input name="admin_name" id="adminName" type="text" autocomplete="off" lay-verify="required" placeholder="请输入管理员姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">护工ID</label>
                    <div class="layui-input-inline">
                        <input name="hg_id" id="hgID" type="text" autocomplete="off" lay-verify="required" placeholder="请输入护工ID" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">护工姓名</label>
                    <div class="layui-input-inline">
                        <input name="hg_name" id="hgName" type="text" autocomplete="off" lay-verify="required" placeholder="请输入护工姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">检查时间</label>
                    <div class="layui-input-inline">
                        <input name="check_time" id="checkdate"  type="text" autocomplete="off" lay-verify="required" placeholder="请输入飞行检查时间" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label">检查结果</label>
                    <div class="layui-input-inline">
                        <select name="checkResult" id="checkresult"  >
                            <option value="">请选择</option>
                            <option value="1">正常</option>
                            <option value="2">异常</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">文件上传</label>
                    <div class="layui-input-inline">
                        <input type="file"  name="uploadfile" id="recordFile"  class="layui-input">
                        <%--隐藏传文件地址  --%>
                        <input type="hidden" name="recordfile" id="filePath" class="layui-input" >
                    </div>
                </div>


                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">描述</label>
                    <div class="layui-input-block">
                        <textarea type="text" id="checkDescribe" name="checkdescribe" placeholder="请添加描述" class="layui-textarea"></textarea>
                    </div>
                </div>


                <%-- 上传文件--%>
                <script>

                    layui.use('upload',function (){
                        var $ = layui.jquery
                            ,upload = layui.upload;

                        upload.render({
                            elem: '#recordFile'
                            ,url: '${webPath}/toTempCheck/upload/' //改成您自己的上传接口
                            ,accept: 'file' //视频文件
                            //,auto:true
                            // ,bindAction:"#save_btn"
                            ,done: function(res){
                                $("#filePath").val(res.extend.path);//后端传递过来的保存的文件地址
                                layer.msg('上传成功');
                                console.log(res)
                            }
                            , error: function (res) {
                                //请求异常回调
                                console.error(res);
                            }
                        });
                    })

                </script>

            </form>

            <div  style="text-align:center">
                <button  type="submit" id="save_btn" class="layui-btn"  >立即提交</button>
            </div>



            <script id="view" type="text/html">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>权限名称</th>
                    <th>权限分类</th>
                    <th>权限路径</th>
                    <th>权限code</th>
                    <th>优先级</th>
                    <th style="width:140px;">操作</th>
                </tr>
                </thead>
                <tbody>
                {{# layui.each(d.rows,function(index,r){ }}
                <tr>
                    <td>{{r.name}}</td>
                    <td>{{r.istype==0?'菜单':(r.istype==1?'功能':'权限')}}</td>
                    <td>{{r.page}}</td>
                    <td>{{r.code}}</td>
                    <td>{{r.zindex}}</td>
                    <td><a class="layui-btn layui-btn-primary layui-btn-xs"
                           onclick="edit('{{r.id}}',0);">编辑</a>
                        <a class="layui-btn layui-btn-xs" onclick="addPerm('{{r.id}}',1)">添加子节点</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs"
                           onclick="del('{{r.id}}','{{r.name}}')">删除</a>
                    </td>
                </tr>
                {{# }); }}
                </tbody>
            </table>
        </script>
    </div>

    <!--编辑权限 0-->
    <div id="updatePerm" class="layer_self_wrap" style="width:500px;display:none;">
        <form id="permForm" class="layui-form" method="post" action=""
              style="margin-top: 20px;">
            <input id="type" type="hidden" name="type"/>
            <input id="pid" type="hidden" name="pid"/>
            <input id="id" type="hidden" name="id"/>
            <div class="layui-form-item">
                <label class="layui-form-label">权限名称</label>
                <div class="layui-input-inline">
                    <input name="name" lay-verify="required" autocomplete="off" class="layui-input"
                           type="text"/>
                </div>
            </div>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">权限分类</label>
                <div class="layui-input-block">
                    <%--????--%>
                    <input name="istype" value="0" title="菜单" checked="" type="radio"/>
                    <input name="istype" value="1" title="功能" type="radio"/>
                    <input name="istype" value="2" title="权限" type="radio"/>

                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">权限路径</label>
                <div class="layui-input-inline">
                    <input name="page" lay-verify="required" autocomplete="off" class="layui-input"
                           type="text"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">权限code</label>
                <div class="layui-input-inline">
                    <input name="code" lay-verify="required" autocomplete="off" class="layui-input"
                           type="text"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">权限优先级</label>
                <div class="layui-input-inline">
                    <input name="zindex" autocomplete="off" class="layui-input" type="text"
                           onkeyup="this.value=this.value.replace(/\D/g,'')"
                           onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
                </div>
                <div class="layui-form-mid layui-word-aux">请填写大于0的整数数字</div>
            </div>

            <div class="layui-form-item layui-form-text" style="margin-right: 5%;">
                <label class="layui-form-label">文本域</label>
                <div class="layui-input-block">
                    <textarea name="descpt" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button id="commitbtn" class="layui-btn" lay-submit="" lay-filter="permSubmit">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

    <!--添加子节点 1-->
    <div id="updatePerm1" class="layer_self_wrap" style="width:500px;display:none;">
        <form id="permForm1" class="layui-form" method="post" action=""
              style="margin-top: 20px;">
            <input type="hidden" name="type"/>
            <input type="hidden" name="pid"/>
            <input type="hidden" name="id"/>
            <div class="layui-form-item">
                <label class="layui-form-label">权限名称</label>
                <div class="layui-input-inline">
                    <input name="name" lay-verify="required" autocomplete="off" class="layui-input"
                           type="text"/>
                </div>
            </div>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">权限分类</label>
                <div class="layui-input-block" id="inputRadio">
                    <%--????--%>
                    <input name="istype" value="0" title="菜单" type="radio"/>
                    <input name="istype" value="1" title="功能"  checked="" type="radio"/>
                    <input name="istype" value="2" title="权限" type="radio"/>

                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">权限路径</label>
                <div class="layui-input-inline">
                    <input name="page" lay-verify="required" autocomplete="off" class="layui-input"
                           type="text"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">权限code</label>
                <div class="layui-input-inline">
                    <input name="code" lay-verify="required" autocomplete="off" class="layui-input"
                           type="text"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">权限优先级</label>
                <div class="layui-input-inline">
                    <input name="zindex" autocomplete="off" class="layui-input" type="text"
                           onkeyup="this.value=this.value.replace(/\D/g,'')"
                           onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
                </div>
                <div class="layui-form-mid layui-word-aux">请填写大于0的整数数字</div>
            </div>

            <div class="layui-form-item layui-form-text"  style="margin-right: 5%;">
                <label class="layui-form-label">文本域</label>
                <div class="layui-input-block">
                    <textarea name="descpt" placeholder="请输入内容" class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="permSubmit">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>


<%--    <!--底部-->--%>
<%--    <div id="footer"></div>--%>


    <%--<script src="${webPath}/js/permission/auth/permList.js"></script>--%>

<%--      checkresult命名的input单选框，点击事件--%>
    <script>
        $("input[name=checkresult]").click(function(){
            var result = $(this).val();
            alert(result);
        });
    </script>
    <%--输入检查日期组件    --%>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#checkdate' //指定元素
           });
        });
    </script>

    <script>
        $("#header").load("${webPath}/publicPages/permission/fragments/header.jsp");
        $("#footer").load("${webPath}/publicPages/permission/fragments/footer.jsp");
    </script>
    <script>
        var perm = '${permList}';
        var permList = eval('(' + perm + ')');
        console.log(permList);
        console.log("permIdList:" + typeof(permList));
        console.log(Object.prototype.toString.call(permList));
        //初始化treegrid 页面表格
        var basepath = "/js/treegrid/";
        layui.config({
            base: basepath
        }).use(['laytpl', 'treegrid'], function () {
            var laytpl = layui.laytpl,
                treegrid = layui.treegrid;
            treegrid.config.render = function (viewid, data) {
                var view = document.getElementById(viewid).innerHTML;
                return laytpl(view).render(data) || '';
            };

            var treeForm = treegrid.createNew({
                elem: 'permTable',
                view: 'view',
                data: {rows: permList},
                parentid: 'pid',
                singleSelect: false
            });
            treeForm.build();

        });
    </script>

</div>
</body>
</html>